//
//  CYCollectionMenu.m
//  CreditAddressBook
//
//  Created by Lee on 15/9/15.
//  Copyright (c) 2015年 Lee. All rights reserved.
//

#import "CYCollectionMenu.h"
#import "QBPopupMenu.h"

static QBPopupMenu *_popupMenu;
static ClickAtIndexBlock _block;

@implementation CYCollectionMenu


+ (void)initialize {
    QBPopupMenuItem *item = [QBPopupMenuItem itemWithTitle:@"详情" target:self action:@selector(detailAction)];
    QBPopupMenuItem *item2 = [QBPopupMenuItem itemWithTitle:@"删除" target:self action:@selector(deleteAction)];
    NSArray *items = @[item, item2];
    
    QBPopupMenu *popupMenu = [[QBPopupMenu alloc] initWithItems:items];
    popupMenu.highlightedColor = [[UIColor colorWithRed:0 green:0.478 blue:1.0 alpha:1.0] colorWithAlphaComponent:0.8];
    _popupMenu = popupMenu;
}

+ (void)showInView:(UIView *)view targetRect:(CGPoint)targetPoint clickAtIndex:(ClickAtIndexBlock)clickAtIndex {
    _block = [clickAtIndex copy];
    [_popupMenu showInView:view targetRect:(CGRect){targetPoint, CGSizeZero} animated:YES];
}

+ (void)deleteAction {
    _block(CYIndexSecond);
}

+ (void)detailAction {
    _block(CYIndexFirst);
}

- (void)dealloc {
    _block = nil;
}
@end
